<%@page import="util.file.OperacionSubida"%>
<%@page import="util.StringUtil"%>
<%@page import="com.model.domain.persona.HogarXmlTransferido"%>
<%@page import="com.model.domain.ubicacion.ViviendaXmlTransferido"%>
<%@page import="com.model.domain.proceso.envio.subida.LogXmlTransferido"%>
<%@page import="util.FormatUtil"%>
<%@page import="com.model.domain.ubicacion.Vivienda"%>
<%@page import="com.model.domain.persona.HogarXml"%>
<%@page import="com.model.domain.persona.Hogar"%>
<%@page import="java.util.List"%>
<%@page import="com.model.domain.enaho.reporte.ReporteRecuperacionEnvios"%>
<%@page import="com.view.EstilosReporte"%>
<%@page import="com.view.PaginaReporte"%>

    <style type="text/css">
table#tabla2 tbody tr td {
    text-align:"left"; font-size:7pt; color:#000000
}
    </style>
<%    
    PaginaReporte pagina1 = (PaginaReporte) request.getAttribute("pagina");
    EstilosReporte estilos1 = pagina1.getEstilos();
    String excel1 = (String) request.getAttribute("excel");
    
    ReporteRecuperacionEnvios rep = (ReporteRecuperacionEnvios) request.getAttribute("reporte");
%>
<script language="javascript">
function carga_manual(id_envio,hogar){
    
    verMensajeCarga(true);
    var f = document.getElementById("form1"); 
    f.elements["id_envio"].value = id_envio;
    f.elements["hogar"].value = hogar;
    f.action = "dispatcher?controller=data_campo&action=cargaManualDeRecuperacionEnvios";
    f.submit();
    
    window.scrollTo(0,0);//para ver el mensaje "Cargando"
}       
</script>

<% if(!rep.getFilas().isEmpty()) { %>

<!--<script src="js/jquery/jquery-1.11.1.min.js"></script>-->
<!--<script src="js/jquery/jquery.dataTables.min.js"></script>-->
<script src="js/jquery.dataTables_corregido.js?v=7"></script>
<!--Estos estilo vuelve lento la pagina en IE8-->
<!--<link rel="stylesheet" href="js/jquery/jquery.dataTables.css" type="text/css"/>-->

<script language="javascript">       
      
    $(document).ready(function() {
        $('#tabla2').dataTable( {
            "scrollY": "370",
            "scrollX": true,
            "scrollCollapse": false,
            "paging": false,
            "searching": false,
            "ordering": false
        } );
    } );
</script>


<% } %>


<table id="tabla2" border="1" cellspacing="0" cellpadding="0" class="<%=estilos1.getClase_cab() %>" >		
    <thead>
    <tr class="<%=estilos1.getClase_cab() %>" >
        <th colspan="4" style="font-size:7pt">VIVIENDA</th>
        <th colspan="8" style="font-size:7pt">ARCHIVO TRANSFERIDO</th>
        <th colspan="145" style="font-size:7pt">DATA XML</th>
    </tr> 
    
    <tr class="<%=estilos1.getClase_cab() %>" >
        <th rowspan="3" width="40" style="font-size:7pt">N&deg;</th>
        <th rowspan="3" width="85" style="font-size:7pt">CONGLOMERADO</th>                  
        <th rowspan="3" width="85" style="font-size:7pt">VIVIENDA</th>
        <th rowspan="3" width="85" style="font-size:7pt">XML</th>
        <th rowspan="3" width="60" style="font-size:7pt">IP</th>                  
        <th rowspan="3" width="60" style="font-size:7pt">USUARIO</th>
        <th rowspan="3" width="60" style="font-size:7pt">ORDEN DE ENVIO</th>
        <th rowspan="3" width="85" style="font-size:7pt">ARCHIVO XML</th>
        <th rowspan="3" width="120" style="font-size:7pt">FECHA Y HORA</th>
        <th rowspan="3" width="60" style="font-size:7pt">TAMA&Ntilde;O</th>
        <th rowspan="3" width="60" style="font-size:7pt">EXISTE</th>
        <th rowspan="3" width="80" style="font-size:7pt">MODO DE ENVIO</th>
        <th colspan="29" style="font-size:7pt">H1</th>
        <th colspan="29" style="font-size:7pt">H2</th>
        <th colspan="29" style="font-size:7pt">H3</th>
        <th colspan="29" style="font-size:7pt">H4</th>
        <th colspan="29" style="font-size:7pt">H5</th>
    </tr>     
    
    <tr class="<%=estilos1.getClase_cab() %>" >
        <% dibujarCabecerasHogar(out); %>
        <% dibujarCabecerasHogar(out); %>
        <% dibujarCabecerasHogar(out); %>
        <% dibujarCabecerasHogar(out); %>
        <% dibujarCabecerasHogar(out); %>     
    </tr>
    
    <tr class="<%=estilos1.getClase_cab() %>" >
        <% dibujarCabecerasHogarSiNo(out); %>
        <% dibujarCabecerasHogarSiNo(out); %>
        <% dibujarCabecerasHogarSiNo(out); %>
        <% dibujarCabecerasHogarSiNo(out); %>
        <% dibujarCabecerasHogarSiNo(out); %>
    </tr>
    </thead>
    
    <tbody>
<% 
String color = "";
int x = 0;
for(ViviendaXmlTransferido vxml: rep.getFilas()) {   
    //Descarta los registros sin hogares
    if(vxml.getHogares().isEmpty())
        continue;    
    
    x++;
    color = (x%2==0) && excel1!=null ? "#DDF4FF" : "#FFFFFF" ;
    
    LogXmlTransferido logxml = vxml.getLogXmlTransferido();
    OperacionSubida op = logxml.getOperacionSubida();
%><tr onMouseOver="this.style.backgroundColor = '#CCFFCC';" 
        onmouseout="this.style.backgroundColor = '<%=color %>';" 
        style="background-color:<%=color %>; cursor:pointer" >        
        <td><%=x%></td>
        <td><%=vxml.getConglomerado() %></td>
        <td><%=vxml.getVivienda() %></td>
        <td><%=FormatUtil.format(vxml.isExisteEnXml(),"1","0") %></td>
        <td><%=StringUtil.trim(logxml.getIp()) %></td>
        <td><%=logxml.getUsuario() %></td>
        <td><%=vxml.getOrdenEnvio() %></td>
        <td><%=op.getArchivo().getNombre() %></td>
        <td><%=FormatUtil.formatFechaHora( op.getFecha() ) %></td>
        <td><%=op.getArchivo().getTamanho() %></td>
        <td><%=FormatUtil.format(logxml.isExiste(),"1","0")  %></td>
        <td><%=logxml.getModoEnvio() %></td>        
        <% dibujarValoresHogar(out,vxml.getHogar("1"),excel1); %>
        <% dibujarValoresHogar(out,vxml.getHogar("2"),excel1); %>
        <% dibujarValoresHogar(out,vxml.getHogar("3"),excel1); %>
        <% dibujarValoresHogar(out,vxml.getHogar("4"),excel1); %>
        <% dibujarValoresHogar(out,vxml.getHogar("5"),excel1); %>
    </tr>
<%}%>
    </tbody>
    
</table>

<%!
public void dibujarCabecerasHogar(JspWriter out) throws Exception {
    out.print("<th rowspan='2' width='150' style='font-size:7pt'>ESTADO</th>");
    out.print("<th rowspan='2' width='60' style='font-size:7pt'>RES</th>");
    out.print("<th rowspan='2' width='60' style='font-size:7pt'>PER</th>");
    out.print("<th colspan='2' style='font-size:7pt'>601</th>");//1
    out.print("<th colspan='2' style='font-size:7pt'>602</th>");//2
    out.print("<th colspan='2' style='font-size:7pt'>602A</th>");
    out.print("<th colspan='2' style='font-size:7pt'>603</th>");
    out.print("<th colspan='2' style='font-size:7pt'>604</th>");
    out.print("<th colspan='2' style='font-size:7pt'>605</th>");
    out.print("<th colspan='2' style='font-size:7pt'>606</th>");
    out.print("<th colspan='2' style='font-size:7pt'>606D</th>");//8
    out.print("<th colspan='2' style='font-size:7pt'>607</th>");
    out.print("<th colspan='2' style='font-size:7pt'>609</th>");
    out.print("<th colspan='2' style='font-size:7pt'>610</th>");
    out.print("<th colspan='2' style='font-size:7pt'>611</th>");//12
    out.print("<th colspan='2' style='font-size:7pt'>612</th>");//13
}

public void dibujarCabecerasHogarSiNo(JspWriter out) throws Exception {
    for(int i=0; i<13; i++) {
        out.print("<th width='60' style='font-size:7pt'>SI</th>");
        out.print("<th width='60' style='font-size:7pt'>NO</th>");
    }
}

public void dibujarValoresHogar(JspWriter out, HogarXmlTransferido h, String excel) throws Exception {
    
    String link;
    if(h!=null) {
        link = h.getUltimaCarga().getEstadoCarga();
        
        if(h.isPuedeCargarRecuperacion()) {
            link += "&nbsp;";
            
            String msg = "(CARGA MANUAL)";
            if(excel==null) {
                Integer id_envio = h.getViviendaXmlTransferido().getLogXmlTransferido().getId();
                Integer hogar = h.getHogar().getCodigo();
                link += "<a href=javascript:carga_manual("+id_envio+","+hogar+")> "+msg+" </a>";   
            }
            else
                link += msg;
        }                    
    }
    else
        link ="";
    
    out.print("<td>"+ link +"</td>");//1
    
    out.print("<td>"+ (h==null? "" : h.getHogar().getResultadoFinal()) +"</td>");//2
    out.print("<td>"+ (h==null? "" : h.getHogar().getNroMiembros()) +"</td>");//3
    out.print("<td>"+ (h==null? "" : h.getCap601().getNroFilasSi()) +"</td>");//4
    out.print("<td>"+ (h==null? "" : h.getCap601().getNroFilasNo()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap602().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap602().getNroFilasNo()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap602A().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap602A().getNroFilasNo()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap603().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap603().getNroFilasNo()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap604().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap604().getNroFilasNo()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap605().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap605().getNroFilasNo()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap606().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap606().getNroFilasNo()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap606D().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap606D().getNroFilasNo()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap607().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap607().getNroFilasNo()) +"</td>");//21
    out.print("<td>"+ (h==null? "" : h.getCap609().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap609().getNroFilasNo()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap610().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap610().getNroFilasNo()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap611().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap611().getNroFilasNo()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap612().getNroFilasSi()) +"</td>");
    out.print("<td>"+ (h==null? "" : h.getCap612().getNroFilasNo()) +"</td>");//29
}
%>